package com.junxonline.plat.controller.wages;

import com.junxonline.common.dao.vo.ResultVO;
import com.junxonline.common.util.CommonUtils;
import com.junxonline.plat.controller.base.BaseController;
import com.junxonline.plat.dao.vo.*;
import com.junxonline.plat.exception.ErrorCodeEnum;
import com.junxonline.plat.service.wages.WagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JunX
 * @ClassName: WagesController
 * @Description: 工资控制器
 */

@RestController
@RequestMapping(value = "/admin/wages")
public class WagesController extends BaseController {

    @Autowired
    private WagesService wagesService;
    
    /**
     * 获取工资数据
     * @param vo
     * @return
     */
    @RequestMapping(value = "/getWages")
    public ResultVO getWages(@RequestBody QueryWagesVO vo) {

        if (CommonUtils.isEmpty(vo.getWagesId())) {
            return getReturnError(ErrorCodeEnum.PARAMS_IS_NULL);
        }

        return getReturnSuccess(wagesService.getWages(vo));
    }

    /**
     * 筛选查询工资数据
     * @param page
     * @param vo
     * @return
     */
    @RequestMapping(value = "/queryWages")
    public PageResultVO queryWages(PageVO page, QueryWagesVO vo) {
        return getReturnSuccess(wagesService.queryWages(page, vo));
    }


    /**
     * 添加工资
     * @param vo
     * @return
     */
    @RequestMapping(value = "/addWages")
    public ResultVO addWages(@RequestBody WagesVO vo) {

        if (CommonUtils.isEmpty(vo) || CommonUtils.isEmpty(vo.getHouseholdId())) {
            return getReturnError(ErrorCodeEnum.PARAMS_IS_NULL);
        }

        boolean success = wagesService.addWages(vo);
        if (!success) {
            return getReturnError(ErrorCodeEnum.SYSTEM_ERROR);
        }

        return getReturnSuccess();

    }

    /**
     * 修改工资
     * @param vo
     * @return
     */
    @RequestMapping(value = "/editWages")
    public ResultVO editWages(@RequestBody WagesVO vo) {
        if (CommonUtils.isEmpty(vo) || CommonUtils.isEmpty(vo.getWagesId()) || CommonUtils.isEmpty(vo.getHouseholdId())) {
            return getReturnError(ErrorCodeEnum.PARAMS_IS_NULL);
        }

        boolean success = wagesService.editWages(vo);
        if (!success) {
            return getReturnError(ErrorCodeEnum.SYSTEM_ERROR);
        }

        return getReturnSuccess();

    }


    /**
     * 删除工资
     * @param vo
     * @return
     */
    @RequestMapping(value = "/delWages")
    public ResultVO delWages(@RequestBody WagesIdsVO vo) {
        if (CommonUtils.isEmpty(vo)) {
            return getReturnError(ErrorCodeEnum.PARAMS_IS_NULL);
        }

        Long[] wagesIdsArray = vo.getWagesIds();

        boolean successMenu = wagesService.delWages(wagesIdsArray);
        if (!successMenu) {
            return getReturnError(ErrorCodeEnum.SYSTEM_ERROR);
        }

        return getReturnSuccess();
    }

    /**
     * 获取员工数据
     * @param vo
     * @return
     */
    @RequestMapping(value = "/getPersonnel")
    public ResultVO getHousehold(@RequestBody QueryHouseholdVO vo) {

        if (CommonUtils.isEmpty(vo.getHouseholdName())) {
            return getReturnSuccess();
        }

        return getReturnSuccess(wagesService.getHousehold(vo));
    }

}
